package view;

import java.awt.Label;
import java.awt.Panel;
import java.util.ArrayList;

import javax.lang.model.element.Element;

/**
 * Klasa zawierajaca cala tresc ze wszystkich typow stron i podstron (dla admin.jsp, client.jsp, page.jsp, index.jsp)
 * @author MODUL FRONTU (WWW)
 *
 */
public class ContentPanel {

	Panel 			content;
	SidebarPanel 	sidebar;
	ArrayList<String[]> strongPoints;
	String 			title;
	String			description;
	
	/**
	 * Konstruktor dla ContentPanel
	 */
	ContentPanel () {		
		content = new Panel();
		sidebar = new SidebarPanel();
		this.strongPoints = new ArrayList<String[]>();	
	}
	
	
	/**
	 * Konstruktor dla ContentPanel z uwzglednieniem typu strony - podzial strona glowa/podstrona
	 * @param ifHomepage (jesli true -> strona glowna, false -> podstrona)
	 */
	ContentPanel (boolean ifHomepage) {
		
		content = new Panel();
		sidebar = new SidebarPanel();


		if (ifHomepage) {	
			this.strongPoints = new ArrayList<String[]>();		
			
			// adding strong points (four circles) [0] - title, [1]-desc
			String[] sPoint1 = {"Get the account", "Get your account <br /> in 10 seconds!"};
			String[] sPoint2 = {"Get the account", "Get your account <br /> in 10 seconds!"};
			String[] sPoint3 = {"Get the account", "Get your account <br /> in 10 seconds!"};
			String[] sPoint4 = {"Get the account", "Get your account <br /> in 10 seconds!"};
			
			strongPoints.add(sPoint1);
			strongPoints.add(sPoint2);
			strongPoints.add(sPoint3);
			strongPoints.add(sPoint4);
			
			// add 
			content.add(new Label("<div class=\"note\">" +
										"<h2>Some informations</h2>" +
										"<p>Lorem Ipsum </p>" +	
								  "</div>"));

			content.add(new Label("<div id=\"image\">" +
										"<p>run<br/>the world!</p>" +
										"<img src=\"images/slideshow/1.jpg\" alt=\"\" />" +
								  "</div>"));
			
			content.add(new Label("<div class=\"note\">" +
										"<h2>Some informations</h2>" +
										"<p>Lorem Ipsum </p>" +	
								  "</div>"));		
		}		
	}
	
	/**
	 * Metoda wyswietlajaca zawartosc poszczegolnych zakladek
	 * @param String title (tytul zakladki)
	 * @param String description (opis)
	 */
	ContentPanel(String title, String description) {
			
		content = new Panel();
		sidebar = new SidebarPanel();
		this.title=title;
		this.description = description;	
		
		if (title.equals("Our offer")) {
			content.add(new Label("<p class=\"introduction\">Some introduction</p>"));
			content.add(new Label("<p>Our offer</p>"));
		}
		else if (title.equals("Contact")) {
			content.add(new Label("<p class=\"introduction\">Some introduction</p>"));
			content.add(new Label("<p>Contact</p>"));
		}
	}
	
	
	/**
	 * Getter dla tytulu strony
	 * @return String title
	 */
	public String getTitle() {
		return title;
	}

	/**
	 * Getter dla opisu strony
	 * @return String description
	 */
	public String getDescription() {
		return description;
	}

	/**
	 * Metoda pobierajaca panele (zawartosc contentPanelu)
	 * @param type
	 * @return
	 */
	@Deprecated
	public String getContentPanel(String type) {

		String panel = "";
		int i = 0;
		
		for (i = 0; i<content.getComponentCount(); i++) {
			
			Label comp = (Label) content.getComponent(i);			
			panel = panel.concat(comp.getText());
		}
		
		return panel;
	}
	
	/**
	 * Getter pobierajacy sidebar
	 * @return SideBarPanel sidebar
	 */
	public SidebarPanel getSidebar() {
		return sidebar;
	}

	/**
	 * Getter dla listy strongPoints
	 * @return ArrayList<String[]> strongPoints
	 */
	public ArrayList<String[]> getStrongPoints() {
		return strongPoints;
	}
	
	/**
	 * Setter ustawiajacy tytul strony
	 * @param String title
	 */
	public void setTitle(String title) {
		this.title = title;
	}

	/**
	 * Setter ustawiajacy opis dla strony
	 * @param String description
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * NAJWAZNIEJSZA FUNKCJA! ;) Laduje tresc zakladek dla panelu admina i panelu klienta w zaleznosci od parametru name. Tutaj sa wszystkie formularze.
	 * @param String name
	 * @return String tabContent (zawartosc tekstowa danej zakladki)
	 */
	public String loadTab(String name) {
		
		String result = "" ;
		
		if (name.equals("user")) {
			result = result.concat("<h3>Add user</h3>");
			result = result.concat("<p>"
								+ "<form action=\"/adminAddUser.html\" method=\"get\">"
								+ "First name: <input type=\"text\" name=\"firstname\">"
								+ "Last name: <input type=\"text\" name=\"lastname\"><br/>"
								+ "Adress: <input type=\"text\" name=\"address\"><br/>"
								+ "Post code: <input type=\"text\" name=\"postcode\"> "
								+ "City: <input type=\"text\" name=\"city\"><br/>"
								+ "Phone: <input type=\"text\" name=\"phone\"><br/>"
								+ "E-mail: <input type=\"text\" name=\"email\"><br/>"
								+ "<input type=\"submit\" value=\"Add new user\">"
								+ "</form>"
								+ "</p>");
			
			result = result.concat("<h3>Delete user</h3>");
			result = result.concat("<p>"
								+ "<form action=\"/adminDeleteUser.html\" >"
								+ "<select name=\"users\">"
								+ "<option value=\"user1\">User 1</option>"
								+ "<option value=\"user2\">User 2</option>"
								+ "<option value=\"user3\">User 3</option>"
								+ "</select>"
								+ "<input type=\"submit\" value=\"Delete choosen user\">"
								+ "</form>"
								+ "</p>");
			
			result = result.concat("<h3>Modify user</h3>");
			result = result.concat("<p>"
									+ "<form action=\"/adminModifyUser.html\" >"
									+ "<select name=\"userToModify\">"
									+ "<option value=\"user1\">User 1</option>"
									+ "<option value=\"user2\">User 2</option>"
									+ "<option value=\"user3\">User 3</option>"
									+ "</select><br/>"
									+ "First name: <input type=\"text\" name=\"firstname\">"
									+ "Last name: <input type=\"text\" name=\"lastname\"><br/>"
									+ "Adress: <input type=\"text\" name=\"adress\"><br/>"
									+ "Post code: <input type=\"text\" name=\"postcode\"> "
									+ "City: <input type=\"text\" name=\"city\"><br/>"
									+ "Phone: <input type=\"text\" name=\"phone\"><br/>"
									+ "E-mail: <input type=\"text\" name=\"email\"><br/>"
									+ "<input type=\"submit\" value=\"Save changes\">"
									+ "</form>"
									+ "</p>");
		}
		else if (name.equals("products")) {
			result = result.concat("<h3>Add new product</h3>");
			result = result.concat("<p>"
								+ "<form action=\"/adminAddProduct.html\" method=\"get\">"
								+ "Name: <input type=\"text\" name=\"name\"><br/>"
								+ "Price: <input type=\"text\" name=\"price\"><br/>"
								+ "<input type=\"submit\" value=\"Add new product\">"
								+ "</form>"
								+ "</p>");
			
			result = result.concat("<h3>Delete product</h3>");
			result = result.concat("<p>"
								+ "<form action=\"/adminDeleteProduct.html\" >"
								+ "<select name=\"products\">"
								+ "<option value=\"product1\">Product 1</option>"
								+ "<option value=\"product2\">Product 2</option>"
								+ "<option value=\"product3\">Product 3</option>"
								+ "</select>"
								+ "<input type=\"submit\" value=\"Delete choosen product\">"
								+ "</form>"
								+ "</p>");
			
			result = result.concat("<h3>Modify selected product</h3>");
			result = result.concat("<p>"
								+ "<form action=\"/adminModifyProduct.html\" method=\"get\">"
								+ "<select name=\"products\">"
								+ "<option value=\"product1\">Product 1</option>"
								+ "<option value=\"product2\">Product 2</option>"
								+ "<option value=\"product3\">Product 3</option>"
								+ "</select><br/>"
								+ "Name: <input type=\"text\" name=\"name\"><br/>"
								+ "Price: <input type=\"text\" name=\"price\"><br/>"
								+ "<input type=\"submit\" value=\"Save changes\">"
								+ "</form>"
								+ "</p>");
		}
		
		else if (name.equals("stat")) {
			result = result.concat("<h3>Statistics</h3>");
			result = result.concat("<p>Soon...</p>");
		}
		
		else if (name.equals("creditLimit")) {
			result = result.concat("<h3>Set credit limit</h3>");
			result = result.concat("<p>"
								+ "<form action=\"/adminSetCreditLimit.html\" >"
								+ "<select name=\"users\">"
								+ "<option value=\"user1\">User 1</option>"
								+ "<option value=\"user2\">User 2</option>"
								+ "<option value=\"user3\">User 3</option>"
								+ "</select><br/>"
								+ "Credit limit: <input type=\"text\" name=\"creditLimit\"><br/>"
								+ "<input type=\"submit\" value=\"Save changes\">"
								+ "</form>"
								+ "</p>");
		}
		
		else if (name.equals("paymentStatus")) {
			result = result.concat("<h3>Set payment status</h3>");
			result = result.concat("<p>"
								+ "<form action=\"/adminSetPaymentStatus.html\" >"
								+ "<select name=\"orders\">"
								+ "<option value=\"order1\">Order 1</option>"
								+ "<option value=\"order2\">Order 2</option>"
								+ "<option value=\"order3\">Order 3</option>"
								+ "</select><br/>"
								+ "Payment status: "
								+ "<select name=\"payStatus\">"
								+ "<option value=\"paid\">Paid</option>"
								+ "<option value=\"pending\">Pending</option>"
								+ "<option value=\"cancelled\">Cancelled</option>"
								+ "<input type=\"submit\" value=\"Save changes\">"
								+ "</form>"
								+ "</p>");
		}

		else if (name.equals("orderVisit")) {
			result = result.concat("<h3>Order visit</h3>" 
								+ "<form action=\"/orderVisit.html\" >"
								+ "Select person: <select name=\"salesRep\">"
								+ "<option value=\"salesRep1\">Sales representative 1</option>"
								+ "</select><br/>"
								+ "Select date: <select name=\"orderDay\">");
			for (int i = 1; i<=31; i++) {
				result = result.concat("<option>" + i +"</option>");
			}
			result = result.concat("</select><select name=\"orderMonth\">");
			
			for (int i = 1; i<=12; i++) 
				result = result.concat("<option>" + i + "</option>");
			result = result.concat("</select><select name=\"orderYear\">");
			
			for (int i = 2013; i<=2020; i++) {
				result = result.concat("<option>" + i +"</option>");
			}
			result = result.concat("</select><br/>");
			
			result = result.concat("<input type=\"submit\" value=\"Save changes\">"
								+ "</form>"
								);
			
		}
		
		else if (name.equals("orderProducts")) {
			result = result.concat("<h3>Order products</h3>" );
			result = result.concat("<p>"
								+ "<form action=\"orderProducts.html\" >"
								+ "Select product: <select name=\"products\">"
								+ "<option value=\"product1\">Product 1</option>"
								+ "<option value=\"product2\">Product 2</option>"
								+ "<option value=\"product3\">Product 3</option>"
								+ "</select></br>"
								+ "Select person: <select name=\"salesRep\">"
								+ "<option value=\"salesRep1\">Sales representative 1</option>"
								+ "<option value=\"salesRep2\">Sales representative 2</option>"
								+ "<option value=\"salesRep3\">Sales representative 3</option>"
								+ "</select><br/>"
								+ "<input type=\"submit\" value=\"Order\">"
								+ "</form>"
								+ "</p>");
		}
		else if (name.equals("creditInfo")) {
			result = result.concat("<h3>Your credit info</h3>" );
			result = result.concat("<p>"
								+ "Your credit balance: "
								+ "<b>0,00</b> zl"
								+ "</p>" );
		}
		
		return result;
		
	}
	
}
